var prefix = jsctx + "/statistics/charge";

var rechargeStatistics = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageChargeStatistics",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 10,
                    pageList: [10],
                    pageNumber: 1,
                    sidePagination: "server",
                    queryParams: function (params) {
                        return {
                            pageSize: params.limit,
                            pageNo: (params.offset / params.limit) + 1,

                            nickname: $("#nickname").val().trim(),
                            outOrderNum: $("#outOrderNum").val().trim(),
                            station: $("#station").val().trim(),
                            gunNum: $("#gunNum").val().trim(),
                            startTime: $("#startTime").val(),
                            endTime: $("#endTime").val(),
                            operator: $("#operator").val()
                        };
                    },
                    columns: [
                        {
                            title: '序号', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'nickname', title: '用户名', width: '100', align: 'left'},
                        {field: 'operatorName', title: '加盟商名称', width: '100', align: 'left'},
                        {field: 'memberId', title: '账号', width: '100', align: 'left',},
                        {
                            field: 'memberType', title: '用户类型', width: '100', align: 'left',
                            formatter: function (value, row, index) {
                                if (value == '3') {
                                    return "加盟商";
                                } else if (value == '2') {
                                    return "渠道商";
                                } else if (value == '1') {
                                    return "企业会员";
                                } else if (value == '0') {
                                    return "个人用户";
                                } else if (value == '32') {
                                    return "加盟商/渠道商";
                                } else if (value == '21') {
                                    return "加盟商/企业会员";
                                } else if (value == '321') {
                                    return "加盟商/渠道商/企业会员";
                                }else if (value == '31') {
                                    return "加盟商/企业会员";
                                }
                            }
                        },
                        {field: 'rechargeCount', title: '充值次数', width: '100', align: 'left'},
                        {field: 'totalRechargeAmount', title: '累计充值金额', width: '100', align: 'left'},
                        {field: 'chargeCount', title: '充电次数', width: '100', align: 'left'},
                        {field: 'totalPower', title: '充电电量', width: '100', align: 'left'},

                        {field: 'totalChargeAmount', title: '累计充电金额', width: '100', align: 'left'},
                        {field: 'totalDiscountAmount', title: '优惠总额', width: '100', align: 'left'},
                        {field: 'totalPayAmount', title: '实付金额', width: '100', align: 'left'},
                        {field: 'refundCount', title: '累计退款次数', width: '100', align: 'left'},
                        {field: 'totalRefundAmount', title: '累计退款金额', width: '100', align: 'left'},
                        {field: 'account', title: '钱包余额', width: '100', align: 'left'},
                        {
                            field: 'giveAccount', title: '权益金余额', width: '100', align: 'left',
                            formatter: function (value, row, index) {
                                return value + row.frozenGiveAccount;
                            }
                        }
                    ]
                });
    }


    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
        load();
    }

    function exportInfo() {
        $.fileDownload(prefix + "/exporListPageChargeStatistics", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                pageSize: $(".page-size").text(),
                pageNo: $('.active .page-link').text(),

                nickname: $("#nickname").val().trim(),
                outOrderNum: $("#outOrderNum").val().trim(),
                station: $("#station").val().trim(),
                gunNum: $("#gunNum").val().trim(),
                startTime: $("#startTime").val(),
                endTime: $("#endTime").val(),
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    };


    return {
        init: init,
        reLoad: reLoad,
        exportInfo: exportInfo
    };
})();

